package com.qcxy.gzy.bean;

import android.text.TextUtils;

import com.google.gson.Gson;

/**
 * 串口命令
 */
public class SerialPortCommand {
    //命令唯一标识（时间戳）
    private Long serialId;
    //命令
    public byte[] command;
    //命令类型
    public String type;

    public SerialPortCommand(Long serialId, byte[] command, String type) {
        this.serialId = serialId;
        this.command = command;
        this.type = type;
    }

    public SerialPortCommand(Long serialId, byte[] command) {
        this(serialId, command, COM_TYPE_NORMAL);
    }

    public SerialPortCommand(byte[] command, String type) {
        this(System.currentTimeMillis(), command, type);
    }

    public SerialPortCommand(byte[] command) {
        this(command, COM_TYPE_NORMAL);
    }

    public SerialPortCommand() {
    }

    public Long getSerialId() {
        return serialId;
    }


    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("命令类型：")
                .append(TextUtils.isEmpty(type) ? COM_TYPE_NORMAL : type)
                .append("--->>>命令：")
                .append(command != null ? new Gson().toJson(command) : "null");
        return builder.toString();
    }

    private static final String COM_TYPE_NORMAL = "normal";//普通
    public static final String COM_TYPE_EM_START = "em-start";//电机启动
    public static final String COM_TYPE_EM_STOP = "em-stop";//电机停止
    public static final String COM_TYPE_EM_WAIT = "em-wait";//电机等待
    public static final String COM_TYPE_EM_RUN = "em-run";//电机运行
    public static final String COM_TYPE_BRAKE_CLOSE = "brake-close";//制动器关闭
    public static final String COM_TYPE_BRAKE_OPEN = "brake-open";//制动器打开
    public static final String COM_TYPE_BRAKE_READ = "brake-status";//制动器读
    public static final String COM_TYPE_EM_READ = "em-status";//电机状态读
    public static final String COM_TYPE_SC_START = "sc-start";//启动刹车
    public static final String COM_TYPE_SC_STOP = "sc-stop";//停止刹车
    public static final String COM_TYPE_SET_POWER = "set-power";//设置力量
    public static final String COM_TYPE_READ_DISTANCE = "distance";//距离读取
}
